﻿package bdz.projects.slab.sections {
	import bdz.common.model.AppEnvironment;
	import bdz.dms.events.DMSEvent;
	import bdz.projects.slab.core.SlabSection;
	import bdz.projects.slab.data.SlabSiteData;
	import flash.events.*;
	import bdz.common.utils.*;
	import fl.transitions.easing.*;
	import flash.net.*;
	import bdz.projects.slab.events.SlabSiteEvent;
	/**
	* ...
	* @author Default
	*/
	public class SlabContact extends SlabSection {
		private var siteData:SlabSiteData = SlabSiteData.getInstance();
		private var env:AppEnvironment = AppEnvironment.getEnv();
		private var cform:SlabContactForm;
		private var cheader:SlabContactHeader;
		private var caddress:SlabContactAddress;
		private var downloader:DownloadMap;
		function SlabContact() {
			
		}
		override protected function initializeComponent(evt:Event):void {
			super.initializeComponent(evt);
			createElements();
		}
		private function onDownloadMap(evt:MouseEvent):void {
			navigateToURL(new URLRequest(env.getSetting("baseURL") + siteData.getSiteInfo().getProperty("slab_map") ), "_blank");
		}
		private function onMessageSent(evt:DMSEvent):void {
			cform.finishProgress("Inquiry sent.");
		}
		private function onSendInquiry(evt:SlabSiteEvent):void {
			cform.showProgress();
			siteData.sendInquiry(evt.data.ssubject, evt.data.smessage, evt.data.semail, onMessageSent);
		}
		private function createElements():void {
			cheader = new SlabContactHeader();
			cheader.alpha = 0;
			cheader.x = 50;
			addChild(cheader);
			cform = new SlabContactForm();
			cform.alpha = 0;
			cform.x = cheader.x;
			cform.y = cheader.y + cheader.height + 10;
			cform.addEventListener(SlabSiteEvent.SEND_INQUIRY, onSendInquiry);
			addChild(cform);
			caddress = new SlabContactAddress();
			
			if (siteData.getSiteInfo().getProperty("email_inquiry") && siteData.getSiteInfo().getProperty("email_inquiry") != ""){
				 caddress.mailto = "For inquiries or to be added in our mailing list, email <a href='mailto:" + siteData.getSiteInfo().getProperty("email_inquiry") + "'>" + siteData.getSiteInfo().getProperty("email_inquiry") + "</a>";
			}
			caddress.description = siteData.getSiteInfo().getProperty("contact_details");
			caddress.x = cheader.x;
			caddress.y = cform.y + cform.height + 10;
			caddress.alpha = 0;
			addChild(caddress);
			if (siteData.getSiteInfo().getProperty("slab_map") && siteData.getSiteInfo().getProperty("slab_map") != "") {
				downloader = new DownloadMap();
				downloader.x = cheader.x + 5;
				downloader.y = caddress.y + caddress.height + 10;
				downloader.alpha = 0;
				addChild(downloader);
				downloader.addEventListener(MouseEvent.CLICK, onDownloadMap);
				TweenLite.to(downloader, .8, { alpha:1, ease:Strong.easeOut, delay:.6 } );
			}
			TweenLite.to(cheader, .8, { alpha:1, ease:Strong.easeOut } );
			TweenLite.to(cform, .8, { alpha:1, ease:Strong.easeOut, delay:.2 } );
			TweenLite.to(caddress, .8, { alpha:1, ease:Strong.easeOut, delay:.4 } );
			
			
		}
	}
	
	
}